package com.zxblog.service.impl;

import com.zxblog.domain.UserNormal;
import com.zxblog.domain.UserNormalKey;
import com.zxblog.mapper.UserNormalMapper;
import com.zxblog.service.NormalUserService;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class NormalUserServiceImpl implements NormalUserService {

    @Autowired
    private UserNormalMapper userNormalMapper;

    @Override
    public List<UserNormal> getUserInfoByName(String userName) {
        userName = "%"+userName+"%";
        UserNormalKey userNormalKey = new UserNormalKey();
        userNormalKey.setUsername(userName);
        return userNormalMapper.vagueSelectByUserName(userNormalKey);
    }

    @Override
    public UserNormal addUser(UserNormal userNormal) {
        userNormalMapper.insertSelective(userNormal);
        return userNormal;
    }

    @Override
    public UserNormal getUserInfoByUid(Integer uid) {
        UserNormalKey key = new UserNormalKey();
        key.setUid(uid);
        return userNormalMapper.selectByPrimaryKey(key);
    }
}
